package cn.gdut.chengcai.base;

import java.text.SimpleDateFormat;
import java.util.List;

import org.apache.commons.beanutils.BeanUtils;

import cn.gdut.chengcai.entity.CommentInfo;
import cn.gdut.chengcai.vo.CommentInfoVo;

public class CommentUtil {

	public static void fillVo(CommentInfo entity, CommentInfoVo vo) throws Exception {
		BeanUtils.copyProperties(vo, entity);
		// 时间
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		vo.setCreateTime(sdf.format(entity.getCreateTime()));
		vo.setUpdateTime(sdf.format(entity.getUpdateTime()));
	}

	public static List<CommentInfoVo> fillVoList(List<CommentInfo> list, List<CommentInfoVo> voList) throws Exception {
		if ((null != list) && (list.size() > 0)) {
			for (CommentInfo entity : list) {
				CommentInfoVo vo = new CommentInfoVo();
				fillVo(entity, vo);
				voList.add(vo);
			}
		}

		return voList;
	}

	/**
	 * 页面新增的评论对象在插入数据库之前先进行一些属性的初始化
	 * 
	 * @param entity
	 * @return
	 */
	/*public static CommentInfo initEntity(CommentInfo entity) {
		entity.setCreateTime(new Date());
		return entity;
	}*/

	/**
	 * 页面新增的回复评论对象在插入数据库之前先进行一些属性的初始化
	 * 
	 * @param parent
	 * @param entity
	 * @return
	 */

	/*public static CommentInfo initEntity(CommentInfo parent, CommentInfo entity) {
		// entity.setType(parent.getType());
		entity.setLevel(parent.getLevel() + 1);
		entity.setReplyNum(0);
		// entity.setAuditResult(1);
		entity.setIsAccused(false);
		entity.setReportType((byte) 0);
		entity.setSupportCount(0);
		entity.setCreateTime(new Date());
		return entity;
	}*/

	/*
	 * public static void fillWholeVo(MineCommentInfo entity, MineCommentInfoVo
	 * vo) { PagerUtil.fillVo(entity, vo);
	 * 
	 * fillVo(entity, vo); }
	 * 
	 * public static void fillVo(MineCommentInfo entity, MineCommentInfoVo vo) {
	 * // 审核类型 if (StringUtil.isEmpty(entity.getAuditResult()) == false) {
	 * vo.setAuditResult(AuditStatus.getString(entity.getAuditResult())); } else
	 * { vo.setAuditResult(AuditStatus.WAIT_AUDIT.getString()); }
	 * 
	 * // 是否被举报 if (StringUtil.isEmpty(entity.getIsAccused()) == false) { if
	 * (entity.getIsAccused() == false) { vo.setIsAccused("否"); } else {
	 * vo.setIsAccused("是"); } }
	 * 
	 * // 举报类型 if (StringUtil.isEmpty(entity.getReportType()) == false) {
	 * vo.setReportType(AccuseType.getString(entity.getReportType()));
	 * vo.setReportTypeIndex(entity.getReportType()); }
	 * 
	 * // 时间 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	 * vo.setCreateTime(sdf.format(entity.getCreateTime())); if
	 * (StringUtil.isEmpty(entity.getFirstAuditTime()) == false) {
	 * vo.setFirstAuditTime(sdf.format(entity.getFirstAuditTime())); } if
	 * (StringUtil.isEmpty(entity.getSecondAuditTime()) == false) {
	 * vo.setSecondAuditTime(sdf.format(entity.getSecondAuditTime())); } if
	 * (StringUtil.isEmpty(entity.getReportTime()) == false) {
	 * vo.setReportTime(sdf.format(entity.getReportTime())); } }
	 * 
	 * public static void fillVoList(List<MineCommentInfo> list,
	 * List<MineCommentInfoVo> voList, MineCommentInfoService service) { for
	 * (MineCommentInfo entity : list) { MineCommentInfoVo vo = new
	 * MineCommentInfoVo(); fillWholeVo(entity, vo);
	 * 
	 * MineCommentInfo condition = new MineCommentInfo();
	 * condition.setParentId(entity.getId()); List<MineCommentInfo>
	 * childMineCommentInfoList = service.findByCondition(condition); if
	 * (childMineCommentInfoList != null && childMineCommentInfoList.size() > 0)
	 * { MineCommentInfoVo firstReplyVo = new MineCommentInfoVo(); // 填充第一条评论
	 * fillWholeVo(service.findById(childMineCommentInfoList.get(0).getId()),
	 * firstReplyVo); vo.setFirstReply(firstReplyVo); //
	 * vo.setFirstReply(fillVo(service.findById(childMineCommentInfoList.get(0).
	 * getId()))); } voList.add(vo); } }
	 * 
	 *//**
		 * 页面新增的评论对象在插入数据库之前先进行一些属性的初始化
		 * 
		 * @param entity
		 * @param commentType
		 * @return
		 */

}
